package com.cnzhy.controller;

import com.cnzhy.entity.CrmAdminUser;
import com.cnzhy.service.UserFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: zhaoyan5
 */
@Slf4j
@RestController
public class CrmAdminUserController {

    /**
     * 注入的是动态代理后的对象
     * Proxy.newProxyInstance(userFeignService.getClass().getClassLoader(), userFeignService.getClass().getInterfaces(), invocationHandler);
     *
     */
    UserFeignService userFeignService;

    @Autowired
    public void setUserFeignService(UserFeignService userFeignService) {
        this.userFeignService = userFeignService;
        log.info("注入userFeignService服务成功");
    }

    /**
     * 直接请求 http://localhost:8500/user/3
     * 通过gateway请求 http://localhost:9001/feign-consumer/user/1 或 http://127.0.0.1:9001/gateway/feign-consumer/user/3
     * 通过zuul请求 http://localhost:8002/api/feign-consumer/user/4
     */
    @GetMapping("user/{userId}")
    public CrmAdminUser getCrmAdminUser(@PathVariable long userId) {
        return userFeignService.getCrmAdminUser(userId);
    }

    /**
     * 直接请求 http://localhost:8500/users
     * 通过gateway请求 http://localhost:9001/feign-consumer/users
     */
    @GetMapping("users")
    public List<CrmAdminUser> getAllCrmAdminUsers() {
        return userFeignService.getAllCrmAdminUsers();
    }

}
